﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AForge_zxing;
using Supermarket;


namespace XLSupermarket.Storehouse.Commodity_Stocks
{
    public partial class Commodity_Stocks : Form
    {
        public Commodity_Stocks()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 查询商品库存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Commodity_Stocks_Load(object sender, EventArgs e)
        {
            try
            {
                string sql = "select * from Merchandise_inventory MI,Goods_Warehousing GW where MI.Bar_code=GW.Bar_code";
                dataGridView1.AutoGenerateColumns = false;
                this.dataGridView1.DataSource = DBHelper.FillData(sql);
            }
            catch (Exception ex) {
                MessageBox.Show("出现错误：" + ex.Message);
            }
        }
        /// <summary>
        /// 查询按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            try { 
            string Bar_code = this.textBox1.Text;
            string sql = string.Format("select * from Merchandise_inventory MI,Goods_Warehousing GW where MI.Bar_code=GW.Bar_code and MI.Bar_code like '%{0}%'", Bar_code);
            this.dataGridView1.AutoGenerateColumns = false;
            this.dataGridView1.DataSource = DBHelper.FillData(sql);
            }
            catch (Exception ex)
            {
                MessageBox.Show("出现错误：" + ex.Message);
            }
        }
        /// <summary>
        /// 关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        /// <summary>
        /// 扫码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {
            try { 
            Form1 AF = new Form1();
            DialogResult result = AF.ShowDialog();
            if (result == DialogResult.OK)
            {
                textBox1.Text = AF.reisbn;
            }
            }
            catch (Exception ex)
            {
                MessageBox.Show("出现错误：" + ex.Message);
            }
        }
    }
}
